home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / amiga / gui / prcgntn1.lha / Precognition / source / TitleBox.c < prev    next >
C/C++ Source or Header  |  1992-12-23  |  5KB  |  222 lines

  1.  
  2. #include "TitleBox.h"
  3. #include "GraphicObjectClass.h"
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include "minmax.h"
  7. #include <graphics/gfxmacros.h>
  8.  
  9. #include <proto/exec.h>
  10. #include <proto/intuition.h>
  11. #include <proto/graphics.h>
  12. #include "amigamem.h"
  13.  
  14.  
  15. tPoint TitleBox_Location( TitleBox *self )
  16. {
  17.    return self->Location;
  18. }
  19.  
  20.  
  21. tPoint TitleBox_SetLocation( TitleBox *self,
  22.                              PIXELS    LeftEdge,
  23.                              PIXELS    TopEdge )
  24. {
  25.    self->Location.x = LeftEdge;
  26.    self->Location.y = TopEdge;
  27.    return self->Location;
  28. }
  29.  
  30. tPoint TitleBox_Size( TitleBox *self )
  31. {
  32.    return self->Size;
  33. }
  34.  
  35. tPoint TitleBox_AskSize( TitleBox      *self,
  36.                          PIXELS         Width,
  37.                          PIXELS         Height )
  38. {
  39.    tPoint size;
  40.  
  41.    size.x = MAX( Width, 6 );
  42.    size.y = MAX( Height, 6 );
  43.    return size;
  44. }
  45.  
  46.  
  47. tPoint TitleBox_SetSize( TitleBox *self,
  48.                          PIXELS    Width,
  49.                          PIXELS    Height )
  50. {
  51.    tPoint size;
  52.  
  53.    size = AskSize( self, Width, Height );
  54.    self->Size.x = size.x;
  55.    self->Size.y = size.y;
  56.  
  57.    pcg_Init3DBox( &self->BoxBorder, 0,0, size.x, size.y,
  58.       self->Pens.BrightPen, self->Pens.DarkPen, NULL );
  59.  
  60.    AlignText( &self->ptext, size );
  61.    return size;
  62. }
  63.  
  64. USHORT TitleBox_DitherPattern[] = { 0x5555, 0xAAAA };
  65.  
  66.  
  67.  
  68. void TitleBox_Render( TitleBox *self,
  69.                       RastPort *RPort )
  70. {
  71.    PIXELS xmin, xmax, ymin, ymax;
  72.  
  73.    xmin = self->Location.x;
  74.    xmax = xmin + self->Size.x - 1;
  75.    ymin = self->Location.y;
  76.    ymax = ymin + self->Size.y - 1;
  77.  
  78.    SetAfPt( RPort, TitleBox_DitherPattern, 1 );
  79.    SetAPen( RPort, self->Pens.BackPen );
  80.    SetBPen( RPort, self->Pens.DarkPen );
  81.    SetDrMd( RPort, JAM2 );
  82.    RectFill( RPort, xmin, ymin, xmax, ymax );
  83.    SetAfPt( RPort, NULL, 0 );
  84.  
  85.  
  86.    DrawBorder( RPort, &self->BoxBorder.TopLeft, xmin, ymin );
  87.  
  88.    SetDrMd( RPort, JAM1 );
  89.    SetAPen( RPort, self->Pens.BrightPen );
  90.  
  91.    PrintIText( RPort, &self->ptext, xmin, ymin  );
  92. }
  93.  
  94. char *TitleBox_Title( TitleBox *self )
  95. {
  96.    return (char*) self->ptext.IText;
  97. }
  98.  
  99. BOOL TitleBox_SetTitle( TitleBox *self, char *title )
  100. {
  101.    Afree(self->ptext.IText);
  102.    self->ptext.IText = Astrdup(title);
  103.    AlignText( &self->ptext, Size(self) );
  104.  
  105.    return TRUE;
  106. }
  107.  
  108. AlignInfo TitleBox_TextAlignment( TitleBox *self )
  109. {
  110.    return self->ptext.alignment;
  111. }
  112.  
  113. AlignInfo TitleBox_SetTextAlignment( TitleBox *self,
  114.                                      UBYTE     Flags,
  115.                                      BYTE      Xpad,
  116.                                      BYTE      Ypad )
  117. {
  118.    self->ptext.alignment.Flags = Flags;
  119.    self->ptext.alignment.Xpad  = Xpad;
  120.    self->ptext.alignment.Ypad  = Ypad;
  121.    AlignText( &self->ptext, Size(self) );
  122.    return self->ptext.alignment;
  123. }
  124.  
  125.  
  126.  
  127.  
  128. #ifdef BUILDER
  129. #include "BuilderMethods.h"
  130. #include "GraphicObject_Builder.h"
  131. #include "TitleBox_coder.h"
  132.  
  133. TitleBox *TitleBox_New( TitleBox *self )
  134. {
  135.    TitleBox *new_box = NULL;
  136.  
  137.    if (new_box = Amalloc(sizeof(TitleBox)))
  138.    {
  139.       TitleBox_Init( new_box, self->Location.x, self->Location.y,
  140.          self->Size.x, self->Size.y, self->Pens, Title(self) );
  141.       GiveItAName( new_box );
  142.    }
  143.  
  144.    return new_box;
  145. }
  146.  
  147. struct BuilderMethods TitleBox_bm;
  148.  
  149. #endif
  150.  
  151. BOOL TitleBox_elaborated = FALSE;
  152.  
  153. struct GraphicObjectClass TitleBox_Class;
  154.  
  155.  
  156. void TitleBoxClass_Init( struct GraphicObjectClass *class )
  157. {
  158.    GraphicObjectClass_Init( class );
  159.    class->isa         = GraphicObjectClass();
  160.    class->ClassName   = "TitleBox";
  161.    class->CleanUp     = NULL; 
  162.    class->Location    = TitleBox_Location;
  163.    class->SetLocation = TitleBox_SetLocation;
  164.    class->Size        = TitleBox_Size;
  165.    class->AskSize     = TitleBox_AskSize;
  166.    class->SetSize     = TitleBox_SetSize;
  167.    class->SizeFlags   = GraphicObject_SizeFlagsAll;
  168.    class->Render      = TitleBox_Render;
  169.    class->SetTitle    = TitleBox_SetTitle;
  170.    class->Title       = TitleBox_Title;
  171.    class->TextAlignment = TitleBox_TextAlignment;
  172.    class->SetTextAlignment = TitleBox_SetTextAlignment;
  173.  
  174. #ifdef BUILDER
  175.    go_InitBuilderMethods( &TitleBox_bm );
  176.    TitleBox_bm.WriteCode = TitleBox_WriteCode;
  177.    TitleBox_bm.New       = TitleBox_New;
  178.    class->BuilderMethods = &TitleBox_bm;
  179. #endif
  180. }
  181.  
  182.  
  183. struct GraphicObjectClass *TitleBoxClass( void )
  184. {
  185.    if (! TitleBox_elaborated)
  186.    {
  187.       TitleBoxClass_Init( &TitleBox_Class );
  188.       TitleBox_elaborated = TRUE;
  189.    }
  190.  
  191.    return &TitleBox_Class;
  192. }
  193.  
  194. void TitleBox_Init( TitleBox    *self,
  195.                     PIXELS       LeftEdge,
  196.                     PIXELS       TopEdge,
  197.                     PIXELS       Width,
  198.                     PIXELS       Height,
  199.                     pcg_3DPens   Pens,
  200.                     char        *Label )
  201. {
  202.    GraphicObject_Init( self );
  203.    
  204.    self->isa         = TitleBoxClass();
  205.    self->Pens        = Pens;
  206.  
  207.    self->ptext.FrontPen  = Pens.BrightPen;
  208.    self->ptext.BackPen   = Pens.BackPen;
  209.    self->ptext.DrawMode  = JAM1;
  210.    self->ptext.ITextFont = &pcg_Topaz80;
  211.    self->ptext.IText     = NULL;
  212.    self->ptext.NextText  = NULL;
  213.  
  214.    self->ptext.alignment.Flags = tx_XCENTER | tx_YCENTER | tx_INSIDE;
  215.    self->ptext.alignment.Xpad  = STD_XPAD;
  216.    self->ptext.alignment.Ypad  = STD_YPAD;
  217.  
  218.    SetLocation( self, LeftEdge, TopEdge );
  219.    SetSize( self, Width, Height );
  220.    SetTitle( self, Label );
  221. }
  222.